<?
	if(!class_exists('Search')) {
		$pathFix = dirname(__FILE__);
		include $pathFix.'/Search.php';
	}

	class Page extends Search {
		var $LinkPageName;
		var $LinkFileName;

		var $LinkField;
		var $LinkString;

		var $PageHtml;

		var $PrevPage;
		var $FirstPage;
		var $Page;
		var $NextPage;
		var $LastPage;

		var $ForStart;
		var $ForEnd;

		var $ShowPageCount;
		var $DescNumber;

		function Page() {
			$this->Search();
			$this->PageHtml = '!';
			$this->ShowPageCount = 10;
			$this->LinkPageName = 'pg';
			$this->Pars = '';
		}

		function __construct() {
			$this->Page();
		}

		function setLinkInfo($getLinkName, $getLinkFileName) {
			if($getLinkFileName!='') {
				$this->LinkFileName = $getLinkFileName;
			}
			if($getLinkName!='') {
				$this->LinkName = $getLinkName;
			}
		}

		function setLinkString($field, $value) {
			unset($this->LinkField);
			$this->LinkField[$field] = $value;
		}

		function addLinkString($field, $value) {
			$this->LinkField[$field] = $value;
		}

		function setPageHtml($getPageHtml) {
			if($getPageHtml!='') {
				$this->PageHtml = $getPageHtml;
			}
		}

		function setShowPageCount($getShowPageCount) {
			if($getShowPageCount!='') {
				$this->ShowPageCount = $getShowPageCount;
			}
		}

		function getLinkString() {
			$LinkString = '';
			if($this->LinkField)foreach($this->LinkField as $Key => $Value) {
				if($Key && $Value) {
					$LinkString .= '&amp;'.$Key.'='.urlencode($Value);
				}
			}
			return $LinkString;
		}

		function countPage() {
			$this->LinkString = $this->LinkFileName.'?';
			$this->LinkString .= $this->getLinkString().$this->getQueryString();
			$this->ForStart = floor($this->ShowPage/$this->ShowPageCount)*$this->ShowPageCount+1;
			if($this->ShowPage%$this->ShowPageCount==0) $this->ForStart-=$this->ShowPageCount;
			$this->ForEnd = $this->ForStart+$this->ShowPageCount;

			// 첫페이지
			if($this->ShowPage>1) {
				$this->FirstPage = 1;
			}

			// 이전페이지
			if($this->ForStart-1 >0) {
				$this->PrevPage = $this->ForStart-1;
			}

			// 다음페이지
			if($this->ForEnd<=$this->AllPageCount) {
				$this->NextPage = $this->ForEnd;
			}

			// 마지막페이지
			if($this->ShowPage<$this->AllPageCount) {
				$this->LastPage = $this->AllPageCount;
			}

		}

		function getPage() {

			// 페이지목록
			for($i=$this->ForStart;$i<$this->ForEnd;$i++) {
				if($this->AllPageCount!=0 && $i > $this->AllPageCount) {
					break;
				}
				if($i!=$this->ShowPage) {
					if($i>=1 && $i<=$this->AllPageCount) {
						$this->Page .= str_replace('#', $i, $this->PageHtml);
					}
				} else {
					$this->Page .= str_replace('#', $i, $this->PageHtml);
				}
			}

		}
		function getRowOrderNumber(&$i) {
			return ($this->AllCount-($this->PageSize*($this->ShowPage-1)))-($i++);
		}

		function PageExcute() {
			$this->getList();
			$this->countPage();
			$this->getPage();
			return $this->Result;
		}
	}
?>